package com.gitee.wsl.common.ui.base

/**
 * An enumeration of the values for units.
 *
 * @since 0.0.1
 */
enum class Units(private val label: String) {
    /** base.  */
    UT(""),

    /** The font size.  */
    EM("em"),

    /** Height of character 'x'.  */
    EX("ex"),

    /** Pixels in user space coordinates.  */
    PX("px"),

    /** Points (1/72 inch).  */
    PT("pt"),

    /** Picas (1/6 inch).  */
    PC("pc"),

    /** Centimeters.  */
    CM("cm"),

    /** Millimeters.  */
    MM("mm"),

    /** Inches.  */
    IN("in");


    override fun toString(): String {
        return label
    }

    fun toString(value: Float):String{
        return "${value}$label"
    }

    fun toString(value: Int):String{
        return "${value}$label"
    }

    fun toString(value: Double):String{
        return "${value}$label"
    }
}

data class UnitValue(var value: Float,var unit: Units = Units.UT){

    val intValue:Int get() = value.toInt()

    constructor(intValue:Int,unit: Units = Units.UT):this(intValue.toFloat(),unit)

    constructor(doubleValue:Double,unit: Units = Units.UT):this(doubleValue.toFloat(),unit)

    override fun toString():String = unit.toString(value)

}

inline val Float.UT: UnitValue
    get() = UnitValue(this, Units.UT)

inline val Float.MM: UnitValue
    get() = UnitValue(this, Units.MM)

inline val Float.EX: UnitValue
    get() = UnitValue(this, Units.EX)

inline val Float.PX: UnitValue
    get() = UnitValue(this, Units.PX)

inline val Float.PT: UnitValue
    get() = UnitValue(this, Units.PT)

inline val Float.PC: UnitValue
    get() = UnitValue(this, Units.PC)

inline val Float.CM: UnitValue
    get() = UnitValue(this, Units.CM)

inline val Float.IN: UnitValue
    get() = UnitValue(this, Units.IN)


inline val Int.UT: UnitValue
    get() = UnitValue(this, Units.UT)

inline val Int.MM: UnitValue
    get() = UnitValue(this, Units.MM)

inline val Int.EX: UnitValue
    get() = UnitValue(this, Units.EX)

inline val Int.PX: UnitValue
    get() = UnitValue(this, Units.PX)

inline val Int.PT: UnitValue
    get() = UnitValue(this, Units.PT)

inline val Int.PC: UnitValue
    get() = UnitValue(this, Units.PC)

inline val Int.CM: UnitValue
    get() = UnitValue(this, Units.CM)

inline val Int.IN: UnitValue
    get() = UnitValue(this, Units.IN)


inline val Double.UT: UnitValue
    get() = UnitValue(this, Units.UT)

inline val Double.MM: UnitValue
    get() = UnitValue(this, Units.MM)

inline val Double.EX: UnitValue
    get() = UnitValue(this, Units.EX)

inline val Double.PX: UnitValue
    get() = UnitValue(this, Units.PX)

inline val Double.PT: UnitValue
    get() = UnitValue(this, Units.PT)

inline val Double.PC: UnitValue
    get() = UnitValue(this, Units.PC)

inline val Double.CM: UnitValue
    get() = UnitValue(this, Units.CM)

inline val Double.IN: UnitValue
    get() = UnitValue(this, Units.IN)

